package com.itheima.mapper;

import com.itheima.pojo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface OrderMapper {
    @Select("SELECT o.id, " +
            "tm.name AS member, " +
            "o.orderType, " +
            "o.orderDate, " +
            "s.name AS setmeal, " +
            "o.setmeal_id AS setmealId " +
            "FROM t_order o " +
            "INNER JOIN t_member tm ON o.member_id = tm.id " +
            "LEFT JOIN t_setmeal s ON o.setmeal_id = s.id " +
            "WHERE o.id = #{id}")
    OrderVO findById(Integer id);


    // 查询指定月份的预约设置数据
    @Select("SELECT * FROM t_ordersetting WHERE DATE_FORMAT(orderDate,'%Y-%m-%d') = #{dateStr}")
    OrderSetting getOrderSettingByMonth(@Param("dateStr") String dateStr);

    // 创建会员
    void createMember(Member member);

    void submitOrder(OrderDTO order);

    @Update("UPDATE t_ordersetting SET number=#{number}, reservations=#{reservations} WHERE id=#{id}")
    void editNumberByOrderDate(OrderSetting orderSetting);

    @Select("SELECT * FROM t_order WHERE member_id=#{memberId} AND orderDate=#{orderDate}")
    Order findByMemberId(OrderDTO order);
}
